<?php

namespace Home\Controller;
//use OT\DataDictionary;
use Home\Model\AdModel;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {

	//系统首页
    public function index(){

//        // 导航列表
//        $channelList = D('channel')->limit(4)->lists();
//        $this->assign('channelList', $channelList);
        // 一级和二级分类树形结构数据
        $cateTree   =   D("Category")->getTree();
        $this->assign('cateTree', $cateTree);
        //var_dump($cateTree);
        # 广告列表数据, 首页位置
        // 导航, sort越大越靠前
        $adList = D('Ad')->order('sort desc')->getAdPositionList(AdModel::POSITION_INDEX_TOP);
        $this->assign('adList', $adList);
        // 首页-进入频道首页1
        $adChannel1 = D('Ad')->order('id desc')->getAdPositionRow(AdModel::POSITION_INDEX_CHANNEL_1);
        $this->assign('adChannel1', $adChannel1);
        // 首页-进入频道首页2
        $adChannel2 = D('Ad')->order('id desc')->getAdPositionRow(AdModel::POSITION_INDEX_CHANNEL_2);
        $this->assign('adChannel2', $adChannel2);
        # 广告列表数据, 首页位置

        # 今日更新位置前8条, 按时间排序
        $todayList = D('Document')->order('id desc')->limit(8)->articleList(null, 'bookmark', 1);
//        FPC($todayList);
//        $todayList = D('Document')->order('id desc')->limit(8)->position(DocumentModel::TPYE_INDEX);
        $this->assign('todayList', $todayList);
        # END-今日更新位置前8条, 按时间排序
        # 每个一级分类下的N条推荐[排序]数据
        $recList = array();
        do{
            $cate = current($cateTree);
            $cateIdStr = $this->getTreeToCateIdStr($cate);
            if($cateIdStr){
                unset($cate['_child']);
                $recList[$cate['name']] = $cate;    // 分类数据
                $recList[$cate['name']]['docList'] = D('Document')->order('id desc')->limit(10)->articleList($cateIdStr, 'bookmark');     // 按时间排序
            }
            $this->assign($cate['name'], $recList[$cate['name']]);  // 对应一级分类指派数据
        }while(next($cateTree) && $cate = current($cateTree));
//        FPC($recList);
//        $this->assign('recList', $recList);
        # END-每个一级分类下的N条推荐[排序]数据

        $this->display();
    }

}